import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getUserInfo } from '@/api/admin/user'
import { removeToken } from '@/composables/cookie'

export const useUserStore = defineStore('user', () => {
    // 用户信息
    const userInfo = ref({})

    // 设置用户信息
    function setUserInfo(){
        getUserInfo().then(res => {
            if(res.success == true){
                userInfo.value = res.data
            }
        })
    }

    // 退出登录
    function logout(){
        removeToken()

        userInfo.value = {}
    }

    return { userInfo, setUserInfo, logout }
},
{
    persist: true,
})